<template>
  <el-drawer
    :title="title"
    v-if="visible"
    :visible.sync="visible"
    direction="rtl"
    size="30%"
    :before-close="handleClose">
    <div class="app-container">
      <el-row>
        <el-col :span="24">
          <el-radio-group v-model="kfjzzx" size="small">
            <el-radio v-for="kf in kangfuPlaceData" :label="kf.kfjzzxId" :key="kf.kfjzzxId" border>{{kf.name}}</el-radio>
          </el-radio-group>
        </el-col>
        <el-col :span="24" style="text-align: center;margin-top: 30px;">
          <el-button type="primary" size="small" @click="submit">保存</el-button>
          <el-button size="small">取消</el-button>
        </el-col>
      </el-row>
    </div>
  </el-drawer>
</template>

<script>

import {queryList} from "@/api/place/kfjzzx";
import {updateKfcs} from "@/api/user/userInfo";

export default {
  name: "UserKfcsSideDrawer",
  props: {
    userId: String
  },
  data() {
    return {
      title: '',
      visible: false,
      loading: false,
      kfjzzx: undefined,
      kangfuPlaceData: []
    }
  },
  methods: {
    open(userInfo) {
      this.kfjzzx = userInfo.kfjzzx
      this.title = '选择吸毒人员康复场所';
      queryList().then(res=> {
        this.kangfuPlaceData = res.data
      }).finally(()=> {
        this.visible = true;
      })
    },
    handleClose() {
      this.visible = false;
      this.$emit('refresh', this.type)
    },
    submit() {
      if (!this.kfjzzx) {
        this.$notify.warning({
          title: '警告',
          message: '请选择康复场所'
        })
        return
      }
      this.$confirm("确定更新吸毒人员康复场所吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        updateKfcs(this.userId, this.kfjzzx).then(res=> {
          this.$message.success('更新吸毒人员康复场所成功')
        }).finally(()=> {
          this.visible = false;
          this.$emit('refresh', this.type)
        })
      }).catch(() => {
      })
    },
  }
}
</script>

<style scoped>

</style>
